﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Xceed.Silverlight.Data
{
  public class HeaderFooterDataItem : DataItem
  {
    public HeaderFooterDataItem( object data, HeaderFooterType type )
      : base( data )
    {
      this.Type = type;
      m_isHeader = ( type == HeaderFooterType.Header );
    }

    public HeaderFooterType Type
    {
      get;
      private set;
    }

    internal bool IsHeader
    {
      get
      {
        return m_isHeader;
      }
    }

    public override int GetHashCode()
    {
      object data = this.Data;

      return ( data != null )
        ? data.GetHashCode()
        : this.Type.GetHashCode();
    }

    public override bool Equals( object obj )
    {
      HeaderFooterDataItem headerDataItem = obj as HeaderFooterDataItem;
      if( headerDataItem == null )
        return false;

      // If there is no data, we have to compare the references of DataItems. 
      // The same thing applies to GetHashCode(). This is necessary because two
      // DataItems can be empty only temporarily and must be considered different
      // for the UI (container generator).
      if( !headerDataItem.IsLoaded || !this.IsLoaded )
        return object.ReferenceEquals( headerDataItem, this );

      object myData = this.Data;
      object otherData = headerDataItem.Data;

      return ( this.Type == headerDataItem.Type )
        && object.Equals( myData, otherData );
    }

    private bool m_isHeader;

    //Empty shell for the class, to be used with Headers/Footers/Group Headers/Group Footers features.
  }
}
